
package com.amigo.online.consumer.merchant.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.amigo.online.common.base.controller.BaseConsumerController;
import com.amigo.online.common.core.response.Response;
import com.amigo.online.common.core.response.StatusCode;
import com.amigo.online.common.param.dto.merchant.CancelCollectDto;
import com.amigo.online.common.param.dto.merchant.GoodsCommentDto;
import com.amigo.online.common.util.CommonValidator;
import com.amigo.online.consumer.merchant.exception.GoodsException;
import com.amigo.online.consumer.merchant.service.MerchantCustomerService;

/**
<code>MerchantCustomerController.java</code>
<p>

</p>
<p>
	@company Amigo
	@author LuChen
	@time 2018年12月17日 下午5:13:32
	@version 1.0 
	@lastUpdate 无
</p>
*/
@RestController
@RequestMapping(value = "/mer", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class MerchantCustomerController extends BaseConsumerController {
	
	
	
	@Autowired
	private MerchantCustomerService merchantCustomerService;
	
	
	/**
	 * 根据id关注商家
	 * @param id 商家id
	 * @return
	 */
	@GetMapping("/concernMer/{id}")
	public ResponseEntity<Response> concernMerchant(@PathVariable("id") Long id){
		return merchantCustomerService.concernMerchant(id);
	}
	
	/**
	 * 根据id取消关注商家
	 * @param id
	 * @return
	 */
	@DeleteMapping("/cancelConcernMer/{id}")
	public ResponseEntity<Response> cancelConcernMerchant(@PathVariable("id") Long id){
		return merchantCustomerService.cancelConcernMerchant(id);
	}
	
	/**
	 * 根据id收藏商品
	 * @param id
	 * @return
	 */
	@GetMapping("/collectGood/{id}")
	public ResponseEntity<Response> collectGoods(@PathVariable("id") Long id){
		return merchantCustomerService.collectGoods(id);
	}
	
	/**
	 * 根据id取消收藏商品
	 * @param id
	 * @return
	 */
	@PostMapping("/cancelCollectGood")
	public ResponseEntity<Response> cancelCollectGoods(@RequestBody CancelCollectDto dto){
		return merchantCustomerService.cancelCollectGoods(dto);
	}
	
	/**
	 * 根据id评论商品
	 * @param id
	 * @return
	 */
	@PostMapping("/commentGood")
	public ResponseEntity<Response> commentGoods(@RequestBody GoodsCommentDto goodsCommentDto){
		if (!CommonValidator.validate(goodsCommentDto)) {
			throw new GoodsException(StatusCode.BAD_REQUEST);
		}
		return merchantCustomerService.commentGoods(goodsCommentDto);
	}
	
	/**
	 * 根据id删除某条评论
	 * @param id
	 * @return
	 */
	@DeleteMapping("/deleteComment/{id}")
	public ResponseEntity<Response> deleteCommentGoods(@PathVariable("id") Long id){
		return merchantCustomerService.deleteCommentGoods(id);
	}
	
	
	/**
	 * 获得关注列表  其中包括统计数
	 * @param page
	 * @param size
	 * @return
	 */
	@GetMapping("/concernMerList/{page}/{size}")
	public ResponseEntity<Response> getConcernMerList(@PathVariable("page") Integer page,@PathVariable("size") Integer size){
		return merchantCustomerService.getConcernMerList(page,size);
	}
	
	
	/**
	 * 获得收藏列表
	 * @param page
	 * @param size
	 * @return
	 */
	@GetMapping("/collectMerList/{page}/{size}")
	public ResponseEntity<Response> getCollectMerList(@PathVariable("page") Integer page,@PathVariable("size") Integer size){
		return merchantCustomerService.getCollectMerList(page,size);
	}
	
	
	/**
	 * 获得用户评论列表信息
	 * @param page
	 * @param size
	 * @return
	 */
	@GetMapping("/commentMerList/{page}/{size}")
	public ResponseEntity<Response> getCommentMerList(@PathVariable("page") Integer page,@PathVariable("size") Integer size){
		return merchantCustomerService.getCommentMerList(page,size);
	}
	
	
	/**
	 * 按照评论类型获得某商品评论列表
	 * @param id	商品id
	 * @param type	评论类型 0 全部  1好评  2差评
	 * @param page	页码
	 * @param size  每页数量
	 * @return  
	 */
	@GetMapping("/commentListByGoodId/{id}/{type}/{status}/{page}/{size}")
	public ResponseEntity<Response> getCommentGoodsList(@PathVariable("id") Integer id,@PathVariable("type") Integer type,@PathVariable("status") Integer status,@PathVariable("page") Integer page,@PathVariable("size") Integer size){
		return merchantCustomerService.getCommentGoodsList(id,type,status,page,size);
	}
	
	/**
	 * 获得首页数据
	 * 
	 * @param page
	 * @param size
	 * @return
	 */
	@GetMapping("/homePage")
	public ResponseEntity<Response> getHomePage() {
		return merchantCustomerService.getHomePage();
	}
	
	/**
	 * 获得首页数据v2
	 * 
	 * @param page
	 * @param size
	 * @return
	 */
	@GetMapping("/v2/homePage")
	public ResponseEntity<Response> getHomePageV2() {
		return merchantCustomerService.getHomePageV2();
	}
	
	
	
	/**
	 * 商户主页
	 * @param merchantId 商户id
	 * @param page 页码
	 * @param size 每页数量
	 * @param type	查询类别 ,1热门   2推荐   3好评率
	 * @return
	 */
	@GetMapping("/merchantHome")
	public ResponseEntity<Response> getMerchantHome(@RequestParam("merchantId") Long merchantId,
			@RequestParam("page") Integer page, @RequestParam("size") Integer size) {
		return merchantCustomerService.getMerchantHome(merchantId,page,size);
	}
	
}

